subroutine denomt1_d(t1, r1, ie, sym)
!use mod_size
use mod_orbit
use mod_symm
use mod_ioff
use mod_iop 
implicit none
integer, intent(in) :: sym
real*8, intent(inout) :: t1(*), r1(*), ie(*)
!
integer i, j, a, b, idx, iofft
integer irrepi, irrepa, numa, numi
integer ioffoa(8), ioffva(8) 
integer ioffob(8), ioffvb(8) 
integer, external :: irpdso, isymoffso
real*8 dtmp
!
ioffoa(1) = 0; ioffob(1) = 0
do irrepi = 1, nirrep - 1
   ioffoa(irrepi + 1) = ioffoa(irrepi) + popa(irrepi) 
   ioffob(irrepi + 1) = ioffob(irrepi) + popb(irrepi) 
enddo
!
ioffva(1) = ioffoa(nirrep) + popa(nirrep)
ioffvb(1) = ioffob(nirrep) + popb(nirrep)
do irrepi = 1, nirrep - 1
   ioffva(irrepi + 1) = ioffva(irrepi) + vrta(irrepi) 
   ioffvb(irrepi + 1) = ioffvb(irrepi) + vrtb(irrepi) 
enddo
!
do irrepi = 1, nirrep
   irrepa = dirprd(irrepi, 1)
!---for AA spin
   numa = vrta(irrepa)
   numi = popa(irrepi)
   iofft = isymoffso(irrepi, 1, vrta, popa, 1) - 1
!$omp parallel do
   do i = 1, numi 
      do a = 1, numa 
           dtmp = ie(ioffoa(irrepi) + i) - ie(ioffva(irrepa) + a)
           dtmp = 1.d0/dtmp
           idx = iofft + (i-1)*numa + a 
           t1(idx) = r1(idx)*dtmp
      enddo
   enddo
!$omp end parallel do
!
enddo 
!
return 
end
 

subroutine denomt2_d(t2, r2, ie, sym, iopab, iopij)
use mod_ioff
use mod_orbit
!use mod_size 
use mod_iop
use mod_symm
implicit none
integer, intent(in) :: sym, iopab, iopij
real*8, intent(inout) :: t2(*), r2(*), ie(*)
!
integer i, j, a, b, irrepi, irrepj, irrepa, irrepb
integer numa, numb, numi, numj, iofft2(8) 
integer irrepab, irrepij, numab, numij, na
integer ioffoa(8), ioffva(8) 
integer ioffob(8), ioffvb(8) 
integer idxa, idxb, idxi, idxj, idx, iofft
integer, external :: irpdso, isymoffso, idsymsoc
real*8 dtmp
real*8, external :: nrm2so
!
na = nva + noa
ioffoa(1) = 0; ioffob(1) = 0
do irrepi = 1, nirrep - 1
   ioffoa(irrepi + 1) = ioffoa(irrepi) + popa(irrepi) 
   ioffob(irrepi + 1) = ioffob(irrepi) + popb(irrepi) 
enddo
!
ioffva(1) = ioffoa(nirrep) + popa(nirrep)
ioffvb(1) = ioffob(nirrep) + popb(nirrep)
do irrepi = 1, nirrep - 1
   ioffva(irrepi + 1) = ioffva(irrepi) + vrta(irrepi) 
   ioffvb(irrepi + 1) = ioffvb(irrepi) + vrtb(irrepi) 
enddo
!
!---------------for ABAB 
iofft2(1) = 1
do irrepij = 1, nirrep - 1
   irrepab = dirprd(irrepij, 1)
   numij = irpdso(irrepij, popa, popb, 1)
   numab = irpdso(irrepab, vrta, vrtb, 1)
   iofft2(irrepij+1) = iofft2(irrepij) + numab*numij
enddo
!
do irrepij = 1, nirrep
   irrepab = dirprd(irrepij, sym)
   numab = irpdso(irrepab, vrta, vrtb, 1)
   numij = irpdso(irrepij, popa, popb, 1)
   do irrepj = 1, nirrep
      irrepi = dirprd(irrepij, irrepj)
      numi = popa(irrepi)
      numj = popb(irrepj)
      do irrepb = 1, nirrep
         irrepa = dirprd(irrepb, irrepab)
         numa = vrta(irrepa)
         numb = vrtb(irrepb)
         iofft = (ioi3(2)-1)/2 +iofft2(irrepij)-1 &
              + (isymoffso(irrepj,irrepij,popa,popb,1)-1)*numab &
              +  isymoffso(irrepb,irrepab,vrta,vrtb,1)-1
         idxa = ioffva(irrepa)
         idxb = na + ioffvb(irrepb)
         idxi = ioffoa(irrepi)
         idxj = na + ioffob(irrepj)
!$omp parallel do
            do j = 1, numj
            do i = 1, numi
            do b = 1, numb
            do a = 1, numa
               idx = iofft + ((j-1)*numi + i-1)*numab &
                          +  (b-1)*numa + a
               dtmp = ie(idxa+a)+ie(idxb+b)-ie(idxi+i)-ie(idxj+j)
               dtmp = -1.d0/dtmp
               t2(idx) = r2(idx)*dtmp
            enddo
            enddo
            enddo
            enddo
!$omp end parallel do
      enddo
   enddo
enddo


return
end
